﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using DLM.Infrastructure.Domain;

namespace DLM.Domain.Model
{
    public class Message : IValidatableObject, IAggregateRoot
    {
        public int MessageID { get; set; }

        [Required(ErrorMessage = "请选择正确的用户")]
        [RegularExpression(@"^[0-9]*$", ErrorMessage = "请输入正确的用户编号！")]
        public int UserID { get; set; }

        [StringLength(20,ErrorMessage="最大长度为20")]
         [Required(ErrorMessage = "标题不允许为空")]
        public string Title { get; set; }

        public string Content { get; set; }

        public bool IsRead { get; set; }
        public System.DateTime CreateDate { get; set; }
        public string Source { get; set; }

        public virtual User User { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (string.IsNullOrEmpty(Title))
            {
                yield return new ValidationResult("消息标题不能为空", new[] { "Title" });
            }
        }
    }
}
